package example.hellosecurity.example.handler;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import java.io.IOException;

/**
 * @ClassName
 * @Describtion:
 * @Author:Chenc
 * @Date:2024/1/17 12:09
 * @Version 1.0
 */
public class MyForwardAuthenticationFailureHandler implements AuthenticationFailureHandler {


    private final String url;

    public MyForwardAuthenticationFailureHandler(String url) {

        this.url = url;
    }

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        response.sendRedirect(url);
    }
}
